package com.dhcc.sdc.cdss.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.cdss.entity.SdcCdssItemStageEntity;
import com.dhcc.sdc.cdss.service.ISdcCdssItemStageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 诊疗方案-阶段 关系表
 * 
 * @ClassName: SdcCdssItemStageController
 * @Description: TODO
 * @author sunyingjie
 * @date 2023-04-06 10:25:59
 */
@Controller
@RequestMapping("${sys.backendPath}/sdc/sdccdssitemstage")
public class SdcCdssItemStageController extends BaseController {

	private String PREFIX = "/backend/cdss/sdccdssitemstage/";

	@Autowired
	private ISdcCdssItemStageService sdcCdssItemStageService;
	

    /**
     * 跳转到诊疗方案-阶段 关系表列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdccdssitemstage.html";
    }
	
    /**
     * 跳转到新增诊疗方案-阶段 关系表
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdccdssitemstage_add.html";
    }
	
	/**
     * 跳转到修改诊疗方案-阶段 关系表
     */
    @RequestMapping("/to_update/{sdcCdssItemStageId}")
    public String toUpdate(@PathVariable Integer sdcCdssItemStageId, Model model) {
        SdcCdssItemStageEntity sdcCdssItemStage = this.sdcCdssItemStageService.selectById(sdcCdssItemStageId);
        model.addAttribute("sdcCdssItemStage",sdcCdssItemStage);
        return PREFIX + "sdccdssitemstage_edit.html";
    }

    /**
     * 获取诊疗方案-阶段 关系表列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcCdssItemStageEntity> page = new PageFactory<SdcCdssItemStageEntity>().defaultPage();
        List<SdcCdssItemStageEntity> result = this.sdcCdssItemStageService.page(page,params);
        page.setRecords((List<SdcCdssItemStageEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增诊疗方案-阶段 关系表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcCdssItemStageEntity sdcCdssItemStage) {
        if (CommonUtil.isOneEmpty(sdcCdssItemStage)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.sdcCdssItemStageService.insert(sdcCdssItemStage);
        return R.ok();
    }

    /**
     * 删除诊疗方案-阶段 关系表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer sdcCdssItemStageId) {
	
        this.sdcCdssItemStageService.deleteById(sdcCdssItemStageId);

        return R.ok();
    }

    /**
     * 修改诊疗方案-阶段 关系表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcCdssItemStageEntity sdcCdssItemStage) {
        if (CommonUtil.isOneEmpty(sdcCdssItemStage)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.sdcCdssItemStageService.updateById(sdcCdssItemStage);
        return R.ok();
    }
	
}
